# -*- coding: utf-8 -*-
from Utils.util import *

def Occupancy_Grid(Map: list) -> list:
    """
    二值地图
    """
    OG_Map = np.zeros((len(Map), len(Map)), dtype=np.uint8)
    row = len(OG_Map)
    for i in range(2, row - 3):
        for j in range(2, row - 3):
            if enough(i, j, Map):
                OG_Map[i, j] = 1
    for i in range(row):
        for j in range(row):
            if OG_Map[i, j] != 1:
                OG_Map[i, j] = 0
    return OG_Map

def enough(x, y, Map) -> bool:
    for i in range(6):
        for j in range(6):
            if Map[x - 2 + i, y - 2 + j] != 255:
                return False
    return True